/*  File Name	: MakeMsgBlock.h
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-7-4
 *  Description:
 */

#ifndef MAKEMSGBLOCK_H_
#define MAKEMSGBLOCK_H_

#include "MessageBlock.h"

class MakeMsgBlock
{
public:
	MakeMsgBlock(int space_size=0);

	virtual ~MakeMsgBlock();

	int make_block(MessageBlock *mb,int recv_len);

	int get_block(MessageBlock *mb);

	/**
	 * before using,must call init first
	 */
	int init(int space_size=1024*10);

	int space_size(void);

	char *write_ptr(void);

	char *read_ptr(void);

	int left_space(void);

	int next_msg_size(void);
	void reset_space(void);
private:
	char *base_ptr_;
	char *read_ptr_;
	char *write_ptr_;

	int size_;
	int next_msg_size_;
	int storage_len_;
	bool have_left_msg_;

	int endian_;
};

#endif /* MAKEMSGBLOCK_H_ */
